'''
Created on 2010-3-2

@author: Administrator
'''
from jolly.datastructures.AbstractMethod import AbstractMethod
from jolly.datastructures.Queue import Queue

class Deque(Queue):
    '''
    Represents a doubled-ended queue
    '''


    def __init__(self):
        '''
        (Deque)->None
        Constructor.
        '''
        super(Deque, self).__init__()
    
    def getHead(self): pass
    getHead = AbstractMethod(getHead)
    
    head = property(fget=lambda self:self.getHead())
    
    def getTail(self): pass
    getTail = AbstractMethod(getTail)
    tail = property(fget=lambda self:self.getTail())
    
    def enqueueHead(self, obj): pass
    enqueueHead = AbstractMethod(enqueueHead)
    
    def dequeueHead(self): 
        return self.dequeue()
    
    def enqueueTail(self, obj): 
        return self.enqueue(obj)
    
    def dequeueTail(self): pass
    dequeueTail = AbstractMethod(dequeueTail)
    
    @staticmethod
    def test(deque):
        "Deque test program."
        print Deque.test.__doc__
        for i in xrange(6):
            if deque.isFull:
                break
            deque.enqueueHead(i)
            if deque.isFull:
                break
            deque.enqueueTail(i)
        print deque
        print deque.head
        print deque.tail
        while not deque.isEmpty:
            obj = deque.dequeueHead()
            print obj
            if deque.isEmpty:
                break
            obj = deque.dequeueTail()
            print obj
    